/*
day313 
2020.7.6 
*/
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
using namespace std;

 
class Solution {
public:
    int maximumSwap(int num) {
    	stack<int> sta;
    	vector<int> vec1;
		while(num)
		{
			sta.push(num%10);
			num/=10;
		}
		
		while(!sta.empty())
		{
			vec1.push_back(sta.top());
			sta.pop();
		}
		
		vector<int> vec2=vec1;
		sort(vec2.begin(),vec2.end(),[](int a,int b)->bool{
			return a>b;
		});
		
		
		int dif=0;
		while(dif<vec1.size() && vec1[dif]==vec2[dif])
		{
			dif++;
		}
	
		if(dif<vec1.size())
		{
			int tem=vec1.size()-1;
			while(tem>=0 && vec1[tem]!=vec2[dif])
			{
				tem--;
			}
			
			int t=vec1[tem];
			vec1[tem]=vec1[dif];
			vec1[dif]=t;
		}
		
		
		int res=0;
		for(int i=0;i<vec1.size();++i)
		{
			res*=10;
			res+=vec1[i];
		}
		
		return res;
    }
};

int main()
{
	Solution s;
	cout<<s.maximumSwap(2736)<<endl;
	return 0;
}
